<?php
$this->menu = array(
    array('label' => 'Create cargo', 'url' => array('create')),
    array('label' => 'List cargo', 'url' => array('list')),
    array('label' => 'Manage this cargo', 'url' => array('update', 'id' => $model->id)),
    array('label' => 'Delete this cargo', 'url' => array('delete', 'id' => $model->id)),
);
$this->sidebar .= $this->renderPartial('/documents/_uploadportlet',array('id'=>$model->id),true);
?>

<h1>View cargo #<?php echo $model->id; ?></h1>
<div class="view ui-corner-all">

    <b>Cargo information</b>
    <hr />
    <div class="row" id="cargo">
        <?php
        $this->widget('zii.widgets.CDetailView', array(
            'data' => $model,
            'itemCssClass' => array(),
            'attributes' => array(
                'status',
                array(
                    'label' => 'Shipper',
                    'type' => 'html',
                    'value' => CHtml::link(CHtml::encode($model->shipper->cname),
                            array('company/view', 'id' => $model->shipper->id)),
                ),
                array(
                    'label' => 'Consignee',
                    'type' => 'html',
                    'value' => CHtml::link(CHtml::encode($model->consignee->cname),
                            array('company/view', 'id' => $model->consignee->id)),
                ),
                'in_date:date',
                'marking',
                array(
                    'label' => 'Packages',
                    'type' => 'text',
                    'value' => $model->dimension->qty . ' ' . $model->dimension->qty_type . ' / ' . $model->dimension->wt . ' ' . $model->dimension->wt_type . ' / ' . $model->dimension->m3,
                ),
                'invoice_list',
                'courier_list',
                'remark',
            ),
        ));
        ?>
        <br />
    </div>
    <div id="additional_info"><b>Additional informations</b></div>
    <hr />
    <?php
        if ($model->import) {
            $import = array('title' => 'Import', 'view' => '/import/view', 'data' => array('model' => $model->import));
        } else {
            $this->beginClip('import'); ?>
            <div class="row buttons">
        		No import information is being added. Click
        <?php
            $this->widget('zii.widgets.jui.CJuiButton', array(
                'name' => 'create_import',
                'caption' => 'Add info',
                'value' => "create",
            ));
        ?>
            to add import information.
        </div>
    <?php
            $this->endClip();
            $import = array('content' => $this->clips['import'], 'title' => 'Import');
        }
    ?>
    <div id="informations">
        <?php
        $this->widget('application.widgets.RiotingNerds.TabView', array(
            'tabs'=>array(
                'do' => array('title' => 'Package details', 'content' => ''),
                'items' => array('title' => 'Items', 'content' => ''),
                'job' => array('title' => 'Jobs', 'ajax'=>array('jobs/view','id'=>$model->id,'for_model'=>'cargo')),
                'import' => $import,
                'export' => array('title' => 'Export', 'ajax'=>array('cargo/exporttab','id'=>$model->id)),
                'documents'=>array('title'=>'Documents','view'=>'_documents','data'=>array('model'=>$model)),
            ),
        ));
        ?>
    </div>
</div>
<?php
        $cs = Yii::app()->getClientScript();
        $itemUrl = CHtml::normalizeUrl(array('cargo_item/viewall', 'cargo_id' => $model->id));
        
        $ImportUrl = CHtml::normalizeUrl(array('import/create', 'cargo_id' => $model->id));
        $script = <<<EOD
        $('#testing').click(function(){
            $.simplelogajax.notification('testing');
        });
$('#ajaxPortlet li a#menu_item').click(function(){
	var dialogButton = {
		Create:function(){
			var dialog = $(this);
			$.cargo_item_form = {
				afterSubmit:function(data){
					var container = $('#items');
					$(container).subcontent({url:'$itemUrl',show:{method:'html'}});
					$(dialog).dialog('close');
				}
			};
			$(this).find('form').find('[type=submit]').click();
		}
	};
	$.simplelogdialog({url:$(this).attr('href')},{width:600},dialogButton);
	return false;
});
$('#ajaxPortlet li a#menu_collection').click(function(){
	var loadcontent = $.extend($.simplelogcontent,{afterShow:function(){
		var constructor = this;
		$.collection_create_form = {
			afterSubmit:function(data){
				constructor.backstep();
				var container = $('#collection');
				$(container).subcontent({url:'$CollectionUrl',show:{method:'html'},data:{id:data.id}});
			}
		};
	}});
	loadcontent.show($(this).attr('href'));
	return false;
});
$('#ajaxPortlet li a#menu_packing').click(function(){
	var dialogButton = {
		Choose:function(){
			var packing_id = $('[name^=packing_list_c0]:checkbox:checked:last').val();
			$(this).dialog('close');
		}
	};
	$.simplelogdialog({url:$(this).attr('href')},{width:600},dialogButton);
	return false;
});
$('input#create_import').click(function(){
	var original = $(this).parent('div');
	$(original).detach();
	$('#import').subcontent({url:'$ImportUrl',afterShow:function(){
		$('#cancel').replaceWith('<input name="cancel" id="cargo_cancel" type="button" value="Cancel" class="ui-button ui-widget ui-state-default ui-corner-all" role="button" aria-disabled="false">');
		$('#cargo_cancel').click(function(){
			$('#import').html($(original));
		});
	}});
});
EOD;
        $cs->registerScript('cargo#view', $script);
?>